set more off
capture log close 

log using Aldrich_Daniel_JOP_Rep_file, replace 

/*Gender Quotas and the Qualifications of Parliamentarians
The Journal of Politics, 2023
Andrea Aldrich & William Daniel
correspondence: andrea.aldrich@yale.edu
Last Modification 5/3/2023
Stata Version 15.1
Operating System: Micrsoft Windows 10 Enterprise 
*/



/*----------------------------------------------------------------------------//
	Install necessary programs if needed
//----------------------------------------------------------------------------*/
	*outreg2
	*coefplot
	*grc1leg


/*----------------------------------------------------------------------------//
	Choose Wroking Directory
//----------------------------------------------------------------------------*/

 *define directoy to folder were replication was unzipped
	*cd "Your Working Directory here"
	
/*----------------------------------------------------------------------------//
	Main Text Analysis 
//----------------------------------------------------------------------------*/

	use Aldrich_Daniel_2023_PARTY, clear  //this is eduaction data at the PARTY level

/*----------------------------------------------------------------------------//
	Set panel settings
//----------------------------------------------------------------------------*/
		
***set panel settings
	xtset PARTYID WAVE
	encode COUNTRY, generate(ccode)


/*----------------------------------------------------------------------------//
	Figure 1 in main text 
//----------------------------------------------------------------------------*/

	local DV ps_ugrad_min ps_pgrad_min ps_women_ugrad_min ps_women_pgrad_min ps_men_ugrad_min ps_men_pgrad_min 
	
	foreach var in `DV' {
	qui xtreg `var' any_quota i.WAVE if maxrun >=2, fe cluster(ccode)
	est store a5_`var'
	}

local DV ps_ugrad_min ps_pgrad_min ps_women_ugrad_min ps_women_pgrad_min ps_men_ugrad_min ps_men_pgrad_min 
	
	foreach var in `DV' {
	qui xtreg `var' any_quota i.WAVE if maxrun >=2 & nPARTYID>2, fe cluster(ccode)
	est store a6_`var'
	}
	
	*Undergraduate degree	     

	coefplot (a5_ps_ugrad_min, msymbol(diamond)) a6_ps_ugrad_min, title(All MEPs) vertical yline(0) keep(any_quota) legend(order(2 "All Party Delegations" 4 " Party Delegations >2"))
		graph save all_ugrad, replace
			
	coefplot (a5_ps_women_ugrad_min, msymbol(diamond)) a6_ps_women_ugrad_min, title(Women MEPs) vertical yline(0) keep(any_quota) legend(order(2 "All Party Delegations" 4 " Party Delegations >2"))
		graph save women_ugrad, replace

	coefplot (a5_ps_men_ugrad_min, msymbol(diamond)) a6_ps_men_ugrad_min, title(Men MEPs) vertical yline(0) keep(any_quota) legend(order(2 "All Party Delegations" 4 " Party Delegations >2"))
		graph save men_ugrad, replace
			
	grc1leg all_ugrad.gph women_ugrad.gph men_ugrad.gph, title(Undergraduate Degree) col(3) ycommon legendfrom(all_ugrad.gph)
		graph save ugrad_coef, replace
		
	*Postgradaute degree
	
	coefplot (a5_ps_pgrad_min, msymbol(diamond)) a6_ps_pgrad_min, title(All MEPs) vertical yline(0) keep(any_quota) legend(order(2 "All Party Delegations" 4 " Party Delegations >2"))
		graph save all_pgrad, replace
			
	coefplot (a5_ps_women_pgrad_min, msymbol(diamond)) a6_ps_women_pgrad_min, title(Women MEPs) vertical yline(0) keep(any_quota) legend(order(2 "All Party Delegations" 4 " Party Delegations >2"))
		graph save women_pgrad, replace

	coefplot (a5_ps_men_pgrad_min, msymbol(diamond)) a6_ps_men_pgrad_min, title(Men MEPs) vertical yline(0) keep(any_quota) legend(order(2 "All Party Delegations" 4 " Party Delegations >2"))
		graph save men_pgrad, replace
			
	grc1leg all_pgrad.gph women_pgrad.gph men_pgrad.gph, title(Postgraduate Degree) col(3) ycommon legendfrom(all_pgrad.gph)
		graph save pgrad_coef, replace
	
	*both graphs
	grc1leg ugrad_coef.gph pgrad_coef.gph, title() col(1) ycommon legendfrom(ugrad_coef.gph)
		graph save Fig1, replace
		

/*----------------------------------------------------------------------------//
	Figure 2 in main text 
//----------------------------------------------------------------------------*/


	local DV sWomen_ugrad_min sWomen_pgrad_min sMen_ugrad_min sMen_pgrad_min 
	
	foreach var in `DV' {
	qui xtreg `var' any_quota i.WAVE if maxrun >=2, fe cluster(ccode)
	est store a8_`var'
	}
	
	local DV sWomen_ugrad_min sWomen_pgrad_min sMen_ugrad_min sMen_pgrad_min 
	
	foreach var in `DV' {
	qui xtreg `var' any_quota i.WAVE if maxrun >=2 & nPARTYID>2, fe cluster(ccode)
	est store a9_`var'
	}
	
	coefplot(a8_sWomen_ugrad_min) (a9_sWomen_ugrad_min, msymbol(diamond)) , title(Women) vertical yline(0)  keep(any_quota) title(Undergraduate Women) legend(order(2 "All Party Delegations" 4 "Party Delegations >2"))
		graph save a_women_u, replace 
	
	coefplot (a8_sWomen_pgrad_min) (a9_sWomen_pgrad_min, msymbol(diamond)) , title(Women) vertical yline(0) keep(any_quota) title(Postgraduate) legend(order(2 "All Party Delegations" 4 "Party Delegations >2"))
		graph save a_women_p, replace 
	
	grc1leg a_women_u.gph a_women_p.gph,  col(2) ycommon legendfrom(a_women_u.gph)
			graph save a_women, replace
		
	coefplot (a8_sMen_ugrad_min) (a9_sMen_ugrad_min, msymbol(diamond)), title( men) vertical yline(0) title(Undergraduate Men) keep(any_quota)  legend(order(2 "All Party Delegations" 4 " Party Delegations >2"))
		graph save a_men_u, replace	
		
	coefplot (a8_sMen_pgrad_min) (a9_sMen_pgrad_min, msymbol(diamond)), title( men) vertical yline(0)  title(Postgraduate)  keep(any_quota)  legend(order(2 "All Party Delegations" 4 " Party Delegations >2"))
		graph save a_men_p, replace	
			
	grc1leg a_men_u.gph a_men_p.gph, col(2) ycommon legendfrom(a_men_u.gph)
			graph save a_men, replace
		
	grc1leg a_women_u.gph a_men_u.gph, title(Share of Single Gender) col(4) ycommon legendfrom(a_women_u.gph)
		graph save  Figure2, replace

log close 
